package lesson4;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Test {

    static BlockingQueue<Object> blockingQueue = new ArrayBlockingQueue<>(5);

    public static void main(String[] args) {
        Runnable producer = () -> {
           while (true){
               try {
                   System.out.println("producer size : "+blockingQueue.size());
                   blockingQueue.put(new Object());
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        };
        new Thread(producer).start();
        new Thread(producer).start();
        new Thread(producer).start();

        Runnable consumer = () -> {
            while (true){
                try {
                    System.out.println("consumer size : "+blockingQueue.size());
                    blockingQueue.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        new Thread(consumer).start();
    }
}
